﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;

namespace PNut_Project_Lin
{
    public partial class diagdetail : PhoneApplicationPage
    {
        string Name;
        string Detail; // สาเหตุ
        string img; // แก้ไข
        string Link; // เกี่ยวข้อง
        string Web;
        string tbN; 


        List<checkCar> listrepair = new List<checkCar>();

        public diagdetail()
        {
            InitializeComponent();

            listrepair.Add(new checkCar("เปลี่ยนล้อรถยนต์", "", "picture/99.jpg", "http://www.mickku.com/chang_wheels.mp4"));
            listrepair.Add(new checkCar("พ่วงแบตเตอรี่", "", "picture/jump_battery_03.JPEG", "http://www.mickku.com/batteryJump.mp4"));
            listrepair.Add(new checkCar("เปลี่ยนน้ำหม้อน้ำ", "", "picture/9.JPG", "http://www.mickku.com/coolant.mp4"));
            listrepair.Add(new checkCar("เปลี่ยนแบตเตอรี่", "", "picture/car_battery_change.jpg", "http://www.mickku.com/battery.mp4"));
            listrepair.Add(new checkCar("เปลี่ยนน้ำมันเครื่อง", "", "picture/DSCF1362copy.jpg", "http://www.mickku.com/chang_engine_oil.mp4"));


            this.Loaded += new RoutedEventHandler(diagdetail_Loaded);
        }

        void diagdetail_Loaded(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();



        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (NavigationContext.QueryString.TryGetValue("Name", out Name))
            {
                PageTitle.Text = Name;
            }

            if (NavigationContext.QueryString.TryGetValue("Detail", out Detail))
            {
                DetailTb.Text = Detail;
            }

            if (NavigationContext.QueryString.TryGetValue("img", out img))
            {
                DetailfixTb.Text = img;
            }

            if (NavigationContext.QueryString.TryGetValue("Link", out Link))
            {
                for (int i = 0; i < listrepair.Count; i++)
                {
                    if (Link == listrepair.ElementAt(i).Name)
                    {
                        tb1.Text = listrepair.ElementAt(i).Name;
                        im1.Source = new BitmapImage(new Uri(listrepair.ElementAt(i).img,UriKind.Relative));

                        st1.Visibility = System.Windows.Visibility.Visible;
                    }
                }
            }

            if (NavigationContext.QueryString.TryGetValue("Web", out Web))
            {
                for (int i = 0; i < listrepair.Count; i++)
                {
                    if (Web == listrepair.ElementAt(i).Name)
                    {
                        tb2.Text = listrepair.ElementAt(i).Name;
                        im2.Source = new BitmapImage(new Uri(listrepair.ElementAt(i).img, UriKind.Relative));


                        st2.Visibility = System.Windows.Visibility.Visible;
                    }
                }
                if (NavigationContext.QueryString.TryGetValue("tbN", out tbN))
                {
                    PageTitle.Text = tbN;
                }
            }  


        }

        private void st1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            for (int i = 0; i < listrepair.Count; i++)
            {
                if (Link == listrepair.ElementAt(i).Name)
                {
                    NavigationService.Navigate(new Uri("/DetailPage.xaml?Name=" + listrepair.ElementAt(i).Name + "&Detail=" + listrepair.ElementAt(i).Detail + "&img=" + listrepair.ElementAt(i).img + "&Link=" + listrepair.ElementAt(i).Link, UriKind.Relative));
      
   
                }
            }
        }

        private void st2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            for (int i = 0; i < listrepair.Count; i++)
            {
                if (Web == listrepair.ElementAt(i).Name)
                {
                    NavigationService.Navigate(new Uri("/DetailPage.xaml?Name=" + listrepair.ElementAt(i).Name + "&Detail=" + listrepair.ElementAt(i).Detail + "&img=" + listrepair.ElementAt(i).img + "&Link=" + listrepair.ElementAt(i).Link, UriKind.Relative));


                }
            }
        }

        private void st3_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
           NavigationService.Navigate(new Uri("/MapPage.xaml", UriKind.Relative));

        }

        private void st4_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/ServiceCar.xaml", UriKind.Relative));

        }

        private void Map2Bt_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MapPage.xaml", UriKind.Relative));
        }

        private void service2_bt_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/ServiceCar.xaml", UriKind.Relative));
        }
    }
}